package ${package.Service};

import com.lwq.exception.FieldException;
import com.lwq.model.Dto;
import com.lwq.util.BeanAssistant;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};

/**
* Description:
* @author ${author}
* @date ${date}
*/
@Service
public class ${table.serviceName}{

    @Autowired
    private ${table.mapperName} mapper;

    public List<${entity}> queryList(Dto dto){
        return  dto == null? mapper.selectList(null):
                mapper.selectByMap(dto);
    }

    public void add(${entity} model){
        mapper.insert(model);
    }

    public void update(${entity} entity){
        if(entity.getId() == null){
            throw new FieldException("id不可为空");
        }
        ${entity} model = mapper.selectById(entity.getId());
        BeanUtils.copyProperties(entity, model, BeanAssistant.getNullPropertyNames(entity));
        mapper.updateById(model);
    }

    public void del(Long id){
        mapper.deleteById(id);
    }
}